<template>
	<view class="gift-page">
		<view class="top">
			<view class="top_box">
				<view class="top_box_top">
					<image src="/pagesA/payDetail/2.jpg" mode="" class="mini_img"></image>
					<view class="title">
						送礼清单
					</view>
				</view>
				<view class="desc">
					支付后分享给好友收礼
				</view>
			</view>
		</view>
		<view class="gift_list">
			<view class="order-header">
				<text class="order-icon">1</text>
				<text class="order-number">礼包商行</text>
				<text class="order-status">可选择多件商品</text>
			</view>
			<view class="gift_list_center">
				<view class="product-info">
					<view class="product-image">
						<image src="/static/product-image.png" mode="aspectFill"></image>
						<view class="brand-logo">
							<text>ANGZHAI</text>
							<text class="brand-sub">风山</text>
						</view>
						<view class="product-tag">VC黄金百香果美容礼盒</view>
					</view>
					<view class="product-details">
						<view class="product-title">2025头茶果已经上线一纯甜无酸黄金百香果VC之王粉色轻奢礼盒</view>
						<view class="product-true-price">
							￥320起
						</view>
						<view class="product-price">
							<text class="price">¥ 460起</text>
						</view>
					</view>
				</view>
				<view class="product-count">
					<view class="">
						<uni-icons type="trash" size="20"></uni-icons>
					</view>
					<uni-number-box @change="changeValue" />
				</view>
			</view>
			<view class="gift_list_bottom">
				<view class="add-btn">
					<uni-icons type="plus-filled" size="24"></uni-icons> 添加商品
				</view>
			</view>
		</view>
		<view class="user_count">
			<view class="order-header">
				<text class="order-icon">2</text>
				<text class="order-number">收礼人数</text>
				<uni-number-box @change="changeValue" />
			</view>
		</view>
		<view class="gift-detail">
			<view class="gift-detail-item">
				<view class="gift-detail-item-title">
					礼品份数
				</view>
				<view class="gift-detail-item-count">
					1
				</view>
			</view>
			<view class="gift-detail-item">
				<view class="gift-detail-item-title">
					商品总价
				</view>
				<view class="gift-detail-item-count">
					￥320.00
				</view>
			</view>
			<view class="gift-detail-item">
				<view class="gift-detail-item-title">
					运费
				</view>
				<view class="gift-detail-item-count">
					包邮
				</view>
			</view>
		</view>
		<view class="gift-detail" style="    align-items: center;
    display: flex;">
			<image src="/pagesA/payDetail/3.png" mode="" class="icon"></image>微信支付
		</view>
		<view class="btn">
			<view class="btn_left">
				<view class="btn_title">
					实付金额
				</view>
				<view class="btn_detail">
					送给<span>1</span>位好友，共领取<span>1</span>件商品
				</view>
			</view>
			<view class="btn_comfin" @click="wechatPay">
				立即付款
			</view>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '@/utils/request.js';
	export default {
		data() {
			return {};
		},
		methods: {
			changeValue(value) {
				console.log('返回数值：', value);
			},
			wechatPay() {
				let that = this
				wx.login({
					success(res) {
						if (res.code) {
							request({
								url: '/api/user/login/wechat',
								method: 'POST',
								data: {
									code: res.code // ✅ 正确传 code 到后端
								}
							}).then(loginRes => {
								const token = loginRes.data.token;
								const openid = loginRes.data.user.wechat_openid;
								const out_trade_no =
									`ORD${Date.now()}${Math.floor(Math.random() * 10000)}`;
								// ✅ 然后调用支付接口，传 openid
								request({
									url: '/api/pay/unifiedorder',
									method: 'POST',
									data: {
										openid,
										out_trade_no,
										total_fee: 320 * 100
									},
									header: {
										Authorization: token
									}
								}).then(payRes => {
									const {
										timeStamp,
										nonceStr,
										package: pkg,
										signType,
										paySign
									} = payRes.data;

									wx.requestPayment({
										timeStamp,
										nonceStr,
										package: pkg,
										signType,
										paySign,
										success(res) {
											console.log('支付成功', res);
										},
										fail(err) {
											console.error('支付失败', err);
										}
									});
								});
							});
						}
					}
				});

			}
		},
	};
</script>

<style scoped lang="scss">
	.gift-page {
		height: 102vh;
	}

	.top {
		height: 660rpx;
		background-repeat: no-repeat;
	}

	.icon {
		height: 42rpx;
		width: 42rpx;
		border-radius: 50%;
		margin: 0 20rpx 0 30rpx;
	}

	.gift-detail {
		width: 709rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: auto;
		margin-top: 20rpx;
		padding: 40rpx 0;

		.gift-detail-item {
			display: flex;
			justify-content: space-between;
			margin: 20rpx 20rpx 0;

			.gift-detail-item-title {
				font-family: Source Han Sans SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #333333;
			}

			.gift-detail-item-count {
				font-family: Source Han Sans SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #333333;
			}
		}
	}

	.user_count {
		margin: auto;
		margin-top: 20rpx;
		background: white;
		width: 709rpx;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
	}

	.gift_list_bottom {
		display: flex;
		justify-content: center;
		text-align: center;
	}

	.add-btn {
		margin-top: 32rpx;
		text-align: center;
		background: #E0D9E7;
		border-radius: 34rpx;
		font-family: Source Han Sans SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #5A2F83;
		padding: 20rpx 28rpx;
	}

	.gift_list_center {
		border-bottom: 1rpx solid #ECECEC;
	}

	.product-count {
		display: flex;
		justify-content: space-between;
		margin: 0 24rpx;

	}

	.gift_list {
		margin: auto;
		margin-top: -460rpx;
		width: 709rpx;
		height: 562rpx;
		background: #FFFFFF;
		border-radius: 24rpx;

	}

	.order-header {
		display: flex;
		align-items: center;
		padding: 32rpx;
		padding-left: 0;
		border-bottom: 1rpx solid #f0f0f0;

		.order-icon {
			width: 41rpx;
			height: 27rpx;
			background: #F8F0FF;
			margin-right: 10rpx;
			text-align: center;
		}

		.order-number {
			flex: 1;
			font-size: 28rpx;
			color: #333;
		}

		.order-status {
			font-size: 28rpx;
			// color: #00bcd4;
			font-family: Source Han Sans SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #333333;
		}
	}

	.product-info {
		display: flex;
		padding: 32rpx;

		.product-image {
			width: 200rpx;
			height: 200rpx;
			margin-right: 32rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
				border-radius: 16rpx;
				background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%);
			}

			.brand-logo {
				position: absolute;
				top: 16rpx;
				left: 16rpx;
				color: #fff;
				font-size: 24rpx;
				font-weight: bold;

				.brand-sub {
					font-size: 20rpx;
					opacity: 0.8;
				}
			}

			.product-tag {
				position: absolute;
				bottom: 16rpx;
				left: 16rpx;
				color: #fff;
				font-size: 20rpx;
				background: rgba(0, 0, 0, 0.3);
				padding: 8rpx 16rpx;
				border-radius: 8rpx;
			}
		}

		.product-details {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.product-title {
				font-size: 28rpx;
				color: #333;
				line-height: 1.4;
				margin-bottom: 16rpx;
			}

			.product-true-price {
				font-family: Source Han Sans SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #5A2F83;
			}

			.product-price {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.price {
					text-decoration: line-through;
					font-family: Source Han Sans SC;
					font-weight: bold;
					font-size: 24rpx;
					color: #999999;
				}

				.quantity {
					font-size: 28rpx;
					color: #666;
				}
			}
		}
	}

	.top_box {
		margin-top: 186rpx;
		margin-left: 224rpx;

		.top_box_top {
			margin-bottom: 14rpx;
			display: flex;
		}

		.title {
			font-family: Source Han Sans SC;
			font-weight: 500;
			font-size: 44rpx;
			color: #FFFFFF;
		}

		.desc {
			font-family: Source Han Sans SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #FFFFFF;
		}
	}

	.bg_img {
		position: absolute;
		left: 0;
		right: 0;
		width: 100%;
		height: 660rpx;
	}

	.mini_img {
		width: 70rpx;
		height: 70rpx;
	}

	.btn {
		position: fixed;
		bottom: 0;
		display: flex;
		background-color: white;
		width: 750rpx;
		height: 168rpx;
		background: #FFFFFF;
		border-radius: 0rpx;
		justify-content: space-between;

		.btn_left {
			display: flex;
			flex-direction: column;
			margin-top: 36rpx;
			margin-left: 50rpx;

			.btn_title {
				font-family: Source Han Sans SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #333333;
				margin-bottom: 20rpx;
			}

			.btn_detail {
				font-family: Source Han Sans SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #333333;
			}
		}

		.btn_comfin {
			background: #5A2F83;
			border-radius: 40rpx;
			text-align: center;
			padding: 26rpx 46rpx;
			color: white;
			margin-right: 20rpx;
			margin-top: 40rpx;
		}
	}
</style>